package com.ruoyi.business.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.DeliveryBillentry;
import com.ruoyi.business.service.DeliveryBillentryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 发货物料明细Controller
 *
 * @author JerryLu
 * @date 2024/9/7 14:24
 */
@RestController
@RequestMapping("/system/delivery_billentry")
public class DeliveryBillentryController extends BaseController {
    @Autowired
    private DeliveryBillentryService deliveryBillentryService;

    /**
     * 查询发货物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryBillentry deliveryBillentry) {
        startPage();
        List<DeliveryBillentry> list = deliveryBillentryService.queryList(deliveryBillentry);
        return getDataTable(list);
    }

    /**
     * 导出发货物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry:export')")
    @Log(title = "发货物料明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeliveryBillentry deliveryBillentry) {
        List<DeliveryBillentry> list = deliveryBillentryService.queryList(deliveryBillentry);
        ExcelUtil<DeliveryBillentry> util = new ExcelUtil<DeliveryBillentry>(DeliveryBillentry.class);
        util.exportExcel(response, list, "发货物料明细数据");
    }

    /**
     * 获取发货物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(deliveryBillentryService.getById(id));
    }

    /**
     * 获取发货物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:index')")
    @GetMapping(value = "/receiving/{deliveryId}")
    public AjaxResult getReceiptInfo(@PathVariable("deliveryId") String deliveryId) {
        QueryWrapper<DeliveryBillentry> query = Wrappers.query();
        query.eq("delivery_id", deliveryId);
        List<DeliveryBillentry> list = deliveryBillentryService.list(query);
        return success(list);
    }

    /**
     * 新增发货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry:add')")
    @Log(title = "发货物料明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryBillentry deliveryBillentry) {
        return toAjax(deliveryBillentryService.save(deliveryBillentry));
    }

    /**
     * 修改发货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry:edit')")
    @Log(title = "发货物料明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryBillentry deliveryBillentry) {
        return toAjax(deliveryBillentryService.updateById(deliveryBillentry));
    }

    /**
     * 删除发货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry:remove')")
    @Log(title = "发货物料明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(deliveryBillentryService.removeByIds(Arrays.asList(ids)));
    }
}

